package com.xh.demo.feign.fallback;

import com.xh.demo.commons.model.response.R;
import com.xh.demo.feign.OrderServiceFeign;
import com.xh.demo.model.request.OrderCreateRequest;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author wen
 * @apiNote OrderFeignFallback
 * @since 2021-12-11
 */
@Slf4j
@Component
public class OrderFeignFallback implements FallbackFactory<OrderServiceFeign> {

    @Override
    public OrderServiceFeign create(Throwable throwable) {
        log.info("【订单服务调用失败】【{}】", throwable.getMessage());
        return new OrderServiceFeign() {

            @Override
            public R<String> detail(Long id) {
                return R.success("FAILED");
            }

            @Override
            public R<String> detailV2(Long id) {
                return R.success("FAILED");
            }

            @Override
            public R<String> detailV3(Long id) {
                return R.success("detailV3-FAILED");
            }

            @Override
            public R<String> create(Long skuId, OrderCreateRequest request) {
                return R.success("create-order-failed！！！");
            }

        };
    }

}
